<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        textarea {
            vertical-align: middle;
            resize: none;
            outline: slategrey;
            overflow-y: auto;
        }

        .div {
            width: 365px;
            margin: 0 auto;
            /* background-color: aqua; */
        }
        img{
            width:360px;
            height: 190px;
        }
        li{
            position: relative;
        }
        li a{
            position: absolute;
            bottom: 2px;
            right: 5px;
            text-decoration: none;
            color: rgba(0, 0, 0, 0.414);

        }
    </style>
</head>

<body>
    <div class="div">
        <div>
            <img src="/pink/imgs/03.png" alt="">
            <textarea name="" id="" cols="40" rows="3"></textarea>
            <button>发送</button>
        </div>
        <ul>

        </ul>
    </div>
    <script>
        var txt = document.querySelector('textarea')
        var btn = document.querySelector('button')
        var ul = document.querySelector('ul')
        btn.onclick = function () {
            if (txt.value == '') {
                alert('请输入内容....')
                return 0;
            } else {
                console.log(txt.value);
                //  1创建节点
                var li = document.createElement('li')
                li.innerHTML=txt.value +"<a href='javascript:;'>删除</a>"
                //  2添加节点到ul里面
                ul.appendChild(li) //在后面添加
                ul.insertBefore(li,ul.children[0]) //在前面添加
                txt.value=''
            }
           var a= document.querySelectorAll('a')
           for (let i = 0; i < a.length; i++) {
             a[i].onclick=function(){
                ul.removeChild(this.parentNode)
             } 
           }
        }
    </script>
</body>

</html>